<?
/*
 * scrumbrella - Scrum board.
 *
 * Copyright (C) 2009  Gustavo N. Borgoni <gborgoni@voicemedia.com.ar>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

include("include/user.php");
include("layout_config.php");

if ($_SERVER['REQUEST_METHOD'] == "POST") {
	$user = $_REQUEST['user'];
	$pass = $_REQUEST['pass'];

	$userID = user_login($user, $pass);
	if ($userID > 0) {
		session_start();
		$_SESSION['sessid'] = $userID;
		$_SESSION['access_level'] = user_get_accesslevel($userID);
		header("Location: projects.php");
	} else {
		$error_message=_("Authentification failed");
	}
}

if ($_REQUEST['action'] == "logoff") {
	user_logoff();
	$error_message = _("You were logged out.");
}
?>
<html>
	<head>
		<title><?=$layout_project_name; ?> | login</title>
		<link type="text/css" rel="stylesheet" href="themes/<?=$layout_theme?>/main.css" />
	</head>
	<body topmargin="0" leftmargin="0">
		<? include("header.php"); ?>
		<br /><br /><br />
		<center>
		<table width="400" border="0" cellpadding="1" cellspacing="1" align="center">
			<tr>
				<td class="login_title">&nbsp;<strong><?=$layout_project_name." : "._("login"); ?></strong></td>
			</tr>
			<tr>
			<td class="login_window">
			<table width="100%">
			<form method="post" action="login.php" name="login" id="login">
			<tr>
			<td width="100" align="center"><img src="themes/<?=$layout_theme?>/images/login_img.jpg" /></td>
			<td align="right">
				<table width="200" border="0" cellpadding="1" cellspacing="1">
				<tr>
					<td align="right" height="18"><?=_("User")?>:</td>
					<td><input type="text" name="user" id="user" class="login_input"/></td>
				</tr>
				<tr>
					<td align="right" height="18"><?=_("Password")?>:</td>
					<td><input type="password" id="pass" name="pass" class="login_input"/></td>
				</tr>
				<tr>
					<td height="20" colspan="2">
<?php
					if (isset($error_message)) {
?>
					<font color="red"><?=$error_message?></font>
<?
					}
?>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="right">
						<input type="submit" class="bt" value="<?=_("Login")?>" />
					</td>
				</tr>
				</table>
			</td>
			</tr>
			</form>
			</table>
			</td>
			</tr>
		</table>
		</center>
	</body>
</html>
